import java.awt.Color;import java.awt.Font;import java.awt.Frame;import java.awt.Graphics;import javax.swing.JFrame;import javax.swing.JPanel;public class Myclock {public static void main(String args[]){JFrame w=new JFrame();w.setSize(330, 220);w.setLocation(550,350);MyPanel001 mp=new MyPanel001();w.add(mp);Thread t =new Thread(mp);t.start();w.setVisible(true);}}class MyPanel001 extends JPanel implements Runnable{int a=0;int b=0;int c=0;int y=2014;int m=9;int d=16;int q=2;@Overridepublic void paint(Graphics g) {// TODO Auto-generated method stubsuper.paint(g);Font f = new Font("楷体",Font.BOLD,30);g.setFont(f);//设置画笔的格式g.setColor(Color.BLACK);g.drawString("北京时间:",5 ,40); g.setColor(Color.RED); g.drawString(a ":" b ":" c,150 ,40); g.setColor(Color.GREEN); g.drawString("日期:",5 ,100); g.setColor(Color.BLUE); g.drawString(y "年" m "月" d "日",90 ,100); g.setColor(Color.CYAN); g.drawString("星期:",5 ,160); g.setColor(Color.DARK_GRAY); g.drawString(q "",90,160);}@Overridepublic void run() {// TODO Auto-generated method stubwhile(true){c ;if(c>59){c=0;b ;}if(b>59){b=0;a ;}if(a>23){a=0;d ;}if(d>30){d=1;m ;q ;}if(m>12){m=1;y ;}if(q>7){q=0;}try{Thread.sleep((long) 0.000001);}catch(Exception e){}repaint();}}}
评论